package edu.uclm.esi.tysw.tusEntradas.acciones;

import java.sql.SQLException;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.uclm.esi.tysw.tusEntradas.domain.Usuario;

public class LoginAction extends ActionSupport{

	
	private SQLException exception;
	private static final long serialVersionUID = 1L;
	public String execute() {
		try {
			
			String user = ((String[]) ActionContext.getContext().getParameters().get("user"))[0];
			String pass = ((String[]) ActionContext.getContext().getParameters().get("pwd"))[0];
			Usuario admin = new Usuario(user,pass);
			if(admin.usuarioEncontrado(admin)){
				ActionContext.getContext().getSession().put("usuario", "administrador");
				ActionContext.getContext().getSession().put("nomUser", admin.getUsername());
				return SUCCESS;
			}
			else return INPUT;
			
		
		} catch (SQLException e) {
			this.exception=e;
			return ERROR;
		}
	}

}
